﻿CREATE PROCEDURE [audit].[GetTraceInfo]
@Trace SQL_VARIANT, @ID INT=NULL OUTPUT, @Path NVARCHAR (512)=NULL OUTPUT, @Status INT=NULL OUTPUT
AS
BEGIN
	DECLARE @RC int
	SET @RC = 0

	IF(ISNUMERIC(CAST(@Trace AS nvarchar(512))) = 1)
		SET @ID = CAST(@Trace AS int)
	ELSE
	BEGIN
		DECLARE @TraceName nvarchar(256)
		SET @TraceName = CAST(@Trace AS nvarchar(512))

		SET @ID = audit.GetTraceID(@TraceName)
		IF(@ID IS NULL)
		BEGIN
			RAISERROR('The trace (%s) does not exist',1,1,@TraceName)
			GOTO EXIT_PROC
		END
	END

	SET @Path = audit.GetTraceFilePath(@ID)
	IF(@Path IS NULL)
	BEGIN
		RAISERROR('The trace ID (%i) is not valid',16,1,@ID)
		SET @RC = @@ERROR
	END

	SET @Status = audit.GetTraceStatus(@ID)

EXIT_PROC:
	RETURN(@RC)
END